package com.atshiyou.util;

import com.atshiyou.service.impl.ZanNumDaoServiceImpl;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

public class MyFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest)servletRequest;
        HttpServletResponse response = (HttpServletResponse)servletResponse;
        //查询出现在数据库中的点赞数
        ZanNumDaoServiceImpl zanNumDaoService = new ZanNumDaoServiceImpl();
        int num = zanNumDaoService.getNum();
        request.getSession().setAttribute("beginNum",num);
        filterChain.doFilter(servletRequest,servletResponse);
    }

    @Override
    public void destroy() {

    }
}
